﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Login.ascx.cs" Inherits="Parts_Login" %>

<script language="JavaScript" type="text/JavaScript">
<!--
    var detect = navigator.userAgent.toLowerCase();
    checkIt = function (string) { return detect.indexOf(string) + 1; }

    function OpenRDR(url) {
        if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
            var height = screen.availHeight - 50;
            var width = screen.availWidth - 10;
        }
        else if ((screen.Height >= 0) && (screen.Width >= 0)) {
            var height = screen.Height - 90;
            var width = screen.Width - 10;
        }

        if (checkIt('aol')) {
            width = width - 10;
            height = height - 130;
        }

        msg = window.open(url, "rdr", "toolbar=0,status=no,location=no,menubar=no,"
            + "directories=no,scrollbars=no,resizable=no,screenX=0,screenY=0,left=0,"
            + "top=0,width=" + width + ",height=" + height);
    }

    var googleAnalyticsTrans = {
        OrderId: "",
        Total: ""
    }

    function LoginForm() {
        //Username
        if (document.login_form.txtUsername.value == "") {
            //alert("Error: Please enter your username.");
            document.login_form.txtUsername.focus();
            document.getElementById('loginUname').innerHTML = "Vui lòng nhập địa chỉ e-mail.";
            return false;
        }
        else {
            document.getElementById('loginUname').innerHTML = "";
        }

        //Password
        if (document.login_form.txtPassword.value == "") {
            //alert("Error: Please enter your password.");
            document.login_form.txtPassword.focus();
            document.getElementById('loginPass').innerHTML = "Vui lòng nhập mật khẩu.";
            return false;
        }
        else {
            document.getElementById('loginPass').innerHTML = "";
        }

        //submit form
        //login_form.method="post";
        //login_form.action="/account/login-auth.asp"; 
        //login_form.submit();
        var hash_pass = hex_md5(document.login_form.txtPassword.value);
        document.login_form.txtPassword.value = hex_md5(hash_pass + '<%= Session["RandomKey"] %>');
        //document.login_form.txtPassword.value = hash_pass;

        return true;
    }

    function ForgottenPassword() {
        var checkEmail = document.forgot_form.txtEmail.value;
        checkEmail = checkEmail.replace(/ /gi, "");

        if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length - 4) != '.')
                && (checkEmail.charAt(checkEmail.length - 3) != '.'))) {
            //alert("Error: Please enter a valid email address.");
            document.forgot_form.txtEmail.focus();
            document.getElementById('forgotEmail').innerHTML = "Vui lòng nhập địa chỉ e-mail hợp lệ.";
            return false;
        }
        else {
            document.getElementById('forgotEmail').innerHTML = "";
        }

        //submit form
        //forgot_form.method="post";
        //forgot_form.action="/account/forgotten.asp"; 
        //forgot_form.submit();

        return true;
    }

    function ValidateForm() {
        //Email
        var email = document.form_register.txtEmail.value;
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

        if (email == "" || (re.test(email) == false)) {
            document.form_register.txtEmail.focus();
            document.getElementById('divEmail').innerHTML = "Vui lòng nhập địa chỉ e-mail hợp lệ.";
            //window.location = '#txtEmail';
            return false;
        }
        else {
            document.getElementById('divEmail').innerHTML = "";
        }

        //Confirm Email
        if (document.form_register.txtConfirmEmail.value != document.form_register.txtEmail.value) {
            //alert("Error: Your email addresses don't match.");
            document.form_register.txtEmail.focus();
            document.getElementById('divCEmail').innerHTML = "Địa chỉ e-mail không trùng khớp.";
            //window.location = '#txtEmail';
            return false;
        }
        else {
            document.getElementById('divCEmail').innerHTML = "";
        }

        //Password
        if (document.form_register.txtPassword.value == "") {
            //alert("Error: Please enter a password.");
            document.form_register.txtPassword.focus();
            document.getElementById('divPassword').innerHTML = "Vui lòng nhập mật khẩu.";
            //window.location = '#txtPassword';
            return false;
        }
        else {
            document.getElementById('divPassword').innerHTML = ""
        }

        //Confirm Password
        if (document.form_register.txtPassword.value != document.form_register.txtConfirmPass.value) {
            //alert("Error: Your passwords don't match.");
            document.form_register.txtPassword.focus();
            document.getElementById('divCPassword').innerHTML = "Mật khẩu không trùng khớp.";
            //window.location = '#txtPassword';
            return false;
        }
        else {
            document.getElementById('divCPassword').innerHTML = "";
        }

        var hash_pass = hex_md5(document.form_register.txtPassword.value);
        document.form_register.txtPassword.value = hash_pass;
        document.form_register.txtConfirmPass.value = hash_pass;

        return true;
    }

    function showStuff(id) {
        document.getElementById(id).style.display = 'block';
    }

    function checkInput(input1, input2, errLoc, err) {
        if (document.getElementById(input1).value != document.getElementById(input2).value) {
            document.getElementById(errLoc).innerHTML = err + " không trùng khớp.";
        }
        else {
            document.getElementById(errLoc).innerHTML = "";
        }
    }

    function clearError(id) {
        document.getElementById(id).innerHTML = "";
    }
-->
</script>


<div class="account-box-content">     
	<div class="account-box clearfix">
    	<div class="left box floatLeft">
        	<div class="corner tl"></div>
            <div class="corner bl"></div>
			<h3 class="title">Đăng nhập</h3>

<center>
    <p>
        <asp:Label ID="lblLoginMsg" runat="server" ForeColor="Red" Visible="False" 
            Font-Bold="True" Font-Size="Small"></asp:Label>
    </p>
</center>

            <form onsubmit="return LoginForm();" name="login_form" action="" method="post">
                <div class="field-container">
                    <label for="txtUsername" class="label">Tên đăng nhập:</label>
                    <input type="text" class="text-box" name="txtUsername" id="txtUsername"/>
                    <div class="error-msg" id="loginUname"></div>
                </div>
                <div class="field-container">
                    <label for="txtPassword" class="label">Mật khẩu</label>
                    <input type="password" class="text-box" name="txtPassword" id="txtPassword"/>
                    <div class="error-msg" id="loginPass"></div>
                </div>
                <div style="height: 10px;" class="field-container">
                    
                </div>
                <div class="field-container button-container">
                    
                    <div class="button clearfix">
                        <div class="left"></div>
                        <input type="submit" value="Đăng nhập"/>
                        <div class="right"></div>
                    </div>
                </div>
            </form>

            <div style="height: 15px" class="field-container">
                <a class="forgot-password" onclick="showStuff('forgotPassMsg'); showStuff('forgotPass'); showStuff('forgotPassBtn'); return false;" href="#" name="forgotten">Quên mật khẩu?</a>
            </div>
            <div style="height: 20px;display: none;" class="field-container" id="forgotPassMsg">
                <p style="width: 245px;">Nhập địa chỉ email bạn tại đây và mật khẩu sẽ được gửi đến bạn.</p>
            </div>
            <form onsubmit="return ForgottenPassword();" name="forgot_form" action="" method="post">
                <div style="display: none;" class="field-container" id="forgotPass">
                        <label for="txtEmail" class="label">Địa chỉ email:</label>
					    <input class="text-box" id="txtEmail" name="txtEmail"/>
					    <div class="error-msg" id="forgotEmail"></div>
                </div>
                <div style="display: none;" class="field-container button-container" id="forgotPassBtn">
                    <div class="button clearfix">
                        <div class="left"></div>
                        <input type="submit" value="Gửi"/>
                        <div class="right"></div>
                    </div>
                </div>
            </form>
        </div>

        <div class="right box floatLeft">
	        <div class="corner tr"></div>
            <div class="corner br"></div>
			<h3 class="title">Đăng ký</h3>
<center>
    <p>
        <asp:Label ID="lblRegisterMsg" runat="server" ForeColor="Red" Visible="False" 
            Font-Bold="True" Font-Size="Small"></asp:Label>
    </p>
</center>
            <form onsubmit="return ValidateForm();" method="post" action="" name="form_register">
                <input type="hidden" name="act" id="act" value="register" />

                <div class="field-container">
                    <label for="txtName" class="label">Họ tên:</label>
                    <input type="text" value="" class="text-box" name="txtName" id="txtName"/>
                    <div class="error-msg" id="divName"></div>
                </div>
                <div class="field-container">
                    <!--<a name="txtEmail"></a>-->
                    <label for="txtREmail" class="label">Địa chỉ email:</label>
                    <input type="text" value="" class="text-box" name="txtEmail" id="txtREmail"/>
                    <div class="error-msg" id="divEmail"></div>
                </div>
                <div class="field-container">
                    <label for="txtConfirmEmail" class="label">Xác nhận email:</label>
                    <input type="text" onclick="clearError('divCEmail')" onchange="checkInput('txtRConfirmEmail', 'txtREmail', 'divCEmail', 'Email ')" value="" id="txtRConfirmEmail" class="text-box" name="txtConfirmEmail"/>
                    <div class="error-msg" id="divCEmail"></div>
                </div>
                <div class="field-container">
                    <!--<a name="txtPassword"></a>-->
                    <label for="txtRPassword" class="label">Mật khẩu:</label>
                    <input type="password" class="text-box" value="" maxlength="50" id="txtRPassword" name="txtPassword"/>
                    <div class="error-msg" id="divPassword"></div>
                </div>
                <div class="field-container">
                    <label for="txtRConfirmPass" class="label">Xác nhận mật khẩu:</label>
                    <input type="password" class="text-box" onclick="clearError('divCPassword')" onchange="checkInput('txtRConfirmPass', 'txtRPassword', 'divCPassword', 'Password ')" value="" maxlength="50" id="txtRConfirmPass" name="txtConfirmPass"/>
                    <div class="error-msg" id="divCPassword"></div>
                </div>

                <div class="field-container news-about-books-container" style="margin-left:123px;">
                    <label class="label" for="ct">Nhận thông tin sản phẩm mới</label>
                    <input id="ct" type="checkbox" name="ct" value="1" class="styled"/>
                </div>
               
                <div class="field-container">                    
                    <div class="button clearfix">
                        <div class="left"></div>
                        <input type="submit" value="Đăng ký"/>
                        <div class="right"></div>
                    </div>
                </div>
            </form>
        </div>
    </div>        
</div>